package blingking.jfinal.orm.xa;

import com.atomikos.jdbc.AtomikosDataSourceBean;

import javax.sql.DataSource;
import javax.sql.XADataSource;
import java.util.Properties;
/**
 * @author King
 * @description
 * @Date 2020/3/22
 */
public class AtomikosDataSourceBeanBuilder {


    private AtomikosDataSourceBean atomikosDataSourceBean;

    public static AtomikosDataSourceBeanBuilder generBean(){
        return new AtomikosDataSourceBeanBuilder(new AtomikosDataSourceBean());
    }

    public static AtomikosDataSourceBeanBuilder generBean(String name){
        AtomikosDataSourceBean atomikosDataSourceBean = new AtomikosDataSourceBean();
        atomikosDataSourceBean.setUniqueResourceName(name);
        return new AtomikosDataSourceBeanBuilder(atomikosDataSourceBean);
    }

    public AtomikosDataSourceBeanBuilder properties(Properties properties){
        this.atomikosDataSourceBean.setXaProperties(properties);
        return this;
    }

    public AtomikosDataSourceBean build(DataSource dataSource){
        XADataSource xaDataSource = (XADataSource) dataSource;
        this.atomikosDataSourceBean.setXaDataSource(xaDataSource);
        return this.atomikosDataSourceBean;
    }

    private AtomikosDataSourceBeanBuilder(AtomikosDataSourceBean atomikosDataSourceBean) {
        this.atomikosDataSourceBean = atomikosDataSourceBean;
    }

}
